package com.wwt.server.controller;


import com.wwt.server.pojo.Position;
import com.wwt.server.service.IPositionService;
import com.wwt.server.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Tao
 * @since 2021-12-05
 */
@Api(tags = "职位管理控制器")
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    @Autowired
    private IPositionService positionService;
    @GetMapping("/")
    @ApiOperation(value = "获取所有职位信息")
    public Result GetAllPositions(){
        List<Position> positions = positionService.list();
        return Result.success("查询成功",positions);
    }
    @PostMapping("/")
    @ApiOperation(value = "添加职位信息")
    public Result addPositions(@RequestBody Position position){
        position.setCreatedate(LocalDateTime.now());
        boolean result = positionService.save(position);
        if (result)
            return Result.success("插入成功！");
        else
            return Result.fail("插入失败，请重试！");
    }
    @PutMapping("/")
    @ApiOperation(value = "更新职位信息")
    public Result updatePositions(@RequestBody Position position){
        boolean result = positionService.updateById(position);
        if (result)
            return Result.success("更新成功！");
        else
            return Result.fail("更新失败，请重试！");
    }
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除职位信息")
    public Result DeletePositions(@PathVariable Integer id){
        boolean result = positionService.removeById(id);
        if (result)
            return Result.success("删除成功！");
        else
            return Result.fail("删除失败，请重试！");
    }
    @DeleteMapping("/")
    @ApiOperation(value = "批量删除职位信息")
    public Result DeletePositions(Integer[] ids){
        boolean result = positionService.removeByIds(Arrays.asList(ids));
        if (result)
            return Result.success("删除成功！");
        else
            return Result.fail("删除失败，请重试！");
    }
}
